package com.gzwanchuang.lszg.module.account;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.gzwanchuang.lszg.R;
import com.gzwanchuang.lszg.base.BaseActivity;
import com.gzwanchuang.lszg.proto.Recharge;
import com.gzwanchuang.lszg.utils.GsonUtils;
import com.gzwanchuang.lszg.utils.StatusBarUtil;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class TiXianProgressActivity extends BaseActivity {

    Unbinder unbinder;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ti_xian_progress);
        unbinder = ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        tvTitle.setText("提现记录");
        backIv.setOnClickListener(v -> finish());
        initView();
        initListener();
    }

    private void initListener() {
    }

    protected void initView() {
        List<Recharge.My_earnings.wallet_list> lists = GsonUtils.deSerializedFromJson(getIntent().getType(), new TypeToken<List<Recharge.My_earnings.wallet_list>>() {
        }.getType());
        List<Fragment> fragmentList = new ArrayList<>();
        for (Recharge.My_earnings.wallet_list data : lists) {
            fragmentList.add(TiXianProgressFragment.NewInstance(data.getWalletId()));
        }
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return lists.get(position).getWalletName();
            }
        });
        tabLayout.setupWithViewPager(viewPager);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
